package org.zjvis.datascience.web.api;

import cn.weiguangfu.swagger2.plus.annotation.ApiPlus;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.zjvis.datascience.common.dto.TaskInstanceDTO;
import org.zjvis.datascience.common.model.ApiResult;
import org.zjvis.datascience.common.model.ApiResultCode;
import org.zjvis.datascience.common.vo.TaskInstanceVO;
import org.zjvis.datascience.service.TColumnService;

@ApiPlus(value = true)
@RestController
@RequestMapping("/tColumnApi/")
@Api(tags = "tColumnApi", description = "tColumn插件接口")
@Validated
public class TColumnApi {
    @Autowired
    private TColumnService tColumnService;

    @PostMapping(value = "/saveAction")
    @Transactional
    @ResponseBody
    @ApiOperation(value = "saveAction", notes = "saveAction")
    public ApiResult<Void> saveAction(@RequestBody TaskInstanceDTO action) {
        tColumnService.saveAction(action);
        return ApiResult.valueOf(ApiResultCode.SUCCESS);
    }

    @PostMapping(value = "/addOneAction")
    @Transactional
    @ResponseBody
    @ApiOperation(value = "addOneAction", notes = "addOneAction")
    public ApiResult<TaskInstanceDTO> addOneAction(@RequestBody JSONObject params) {
        JSONObject data = params.getJSONObject("data");
        JSONObject vo = JSONObject.parseObject(params.getJSONObject("vo").toJSONString());
        TaskInstanceVO taskInstanceVO = vo.toJavaObject(TaskInstanceVO.class);
        TaskInstanceDTO dto = tColumnService.addOneAction(data, taskInstanceVO);
        return ApiResult.valueOf(dto);
    }

}
